package com.gxa.jjty.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.jjty.admin.mapper.EvaluateConfigMapper;
import com.gxa.jjty.admin.service.EvaluateConfigService;
import com.gxa.jjty.core.pojo.EvaluateConfig;
import com.gxa.jjty.core.service.impl.BaseServiceImpl;

import com.gxa.jjty.core.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @ClassName EvaluateServiceImpl
 * @Author: ws
 * @date 2021/12/8 10:02
 */
@Service("evaluateConfigService")
public class EvaluateConfigServiceImpl extends BaseServiceImpl<EvaluateConfig> implements EvaluateConfigService {

    @Autowired
    EvaluateConfigMapper evaluateConfigMapper;

    @Override
    public PageInfo<EvaluateConfig> selectByPage(Integer page, Integer size) {
        PageHelper.startPage(page, size);

        Example example = new Example(EvaluateConfig.class);
        example.orderBy("createdTime").desc();

        List<EvaluateConfig> evaluateConfigs = evaluateConfigMapper.selectByExample(example);

        return PageInfo.of(evaluateConfigs);
    }

    @Override
    public PageInfo<EvaluateConfig> selectByPage(Integer page, Integer size, String name, String state) {
        PageHelper.startPage(page, size);

        Example example = new Example(EvaluateConfig.class);
        Example.Criteria criteria = example.createCriteria();
        example.orderBy("createdTime").desc();

        if (!StringUtil.isEmpty(name)) {
            criteria.andLike("matterName","%"+ name + "%");
        }
        if ("true".equals(state)){
            criteria.andEqualTo("state",true);
        }if ("false".equals(state)){
            criteria.andEqualTo("state",false);
        }

        List<EvaluateConfig> evaluateConfigs = evaluateConfigMapper.selectByExample(example);

        return PageInfo.of(evaluateConfigs);
    }
}
